﻿using Microsoft.AspNetCore.Mvc;
using SportsPlatform.Dto.SportBusiness.Competition;
using SportsPlatform.SportBusiness.ISportBusiness;
using SportsPlatform.Base;
using SportsPlatform.Query.Competition;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SportsPlatform.Model.SportBusiness;
using SportsPlatform.Filters;
using SportsPlatform.Enums;
using Microsoft.AspNetCore.Authorization;

namespace SportsPlatform.Controllers
{
    /// <summary>
    /// 赛事相关控制器
    /// </summary>

    [ActionAuthorization]
    [Route("api/[controller]/[action]")]
    public class CompetitionController : SportsPlatformControllerBase
    {
        private ICompetitionService _service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public CompetitionController(ICompetitionService service)
        {
            _service = service;
        }

        /// <summary>
        /// 分页获取赛事列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [Log(OperationType.QueryList)]
        [AllowAnonymous]
        public async Task<PagePagingDto<Clientlog>> GetCompetitionPageList([FromBody] GetCompetitionPageListQuery query)
        {
            return await _service.GetCompetitionPageList(query);
        }

        /// <summary>
        /// 新增、修改赛事
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [Log(OperationType.AddOrEditEntity)]
        public async Task<ResultByIdDto> EditCompetition([FromBody] EditCompetitionQuery query)
        {
            return await _service.EditCompetition(query);
        }

        /// <summary>
        /// 关闭赛事
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [Log(OperationType.EditEntity)]
        public async Task<BaseResultDto> CloseCompetition([FromBody] CompetitionIdQuery query)
        {
            return await _service.CloseCompetition(query);
        }

        /// <summary>
        /// 发布赛事
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [Log(OperationType.EditEntity)]
        public async Task<BaseResultDto> ReleaseCompetition([FromBody] CompetitionIdQuery query)
        {
            return await _service.ReleaseCompetition(query);
        }

        /// <summary>
        /// 根据赛事ID获取赛事详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [Log(OperationType.QueryEntity)]
        public async Task<ResultDto<GetCompetitionDetailsDto>> GetCompetitionDetailsById([FromBody] CompetitionIdQuery query)
        {
            return await _service.GetCompetitionDetailsById(query);
        }

        /// <summary>
        /// 获取未关闭的赛事列表
        /// 根据当前用户的公司ID获取用于新增报名时获取未关闭的赛事列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultListDto<GetNotClosedCompetitionListDto>> GetNotClosedCompetitionList()
        {
            return await _service.GetNotClosedCompetitionList();
        }

        /// <summary>
        /// 客户端分页获取赛事信息列表（用于信息同步）
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagePagingDto<GetPageCompetitionKHDDto>> GetPageCompetitionKHD([FromBody] BasePageQuery query)
        {
            return await _service.GetPageCompetitionKHD(query);
        }

        /// <summary>
        /// 客户端赛事信息同步
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> CompetitionSynchronization([FromBody] List<CompetitionSynchronizationQuery> query)
        {
            return await _service.CompetitionSynchronization(query);
        }
    }
}
